$(function () {

    var token = localStorage.wdczy_token;
    var post_url = toRoute('api/account/getPersonInfo');
    $.post(post_url, {'token': token}, function (data) {
        if (data.errorCode == '200') {
            var personInfo = data.data;
            $('.person .top p').html(personInfo.nickName);
            $('.person .top img.photo_pic').attr('src', personInfo.headImg);
            $('#person .tx').attr('src', personInfo.headImg);
        }
    }, 'json');
    AjaxGetOrderList(token);

});

function AjaxGetOrderList(token) {
    var post_url = toRoute('api/order/list');
    $.post(post_url, {'token': token}, function (data) {
        if (data.errorCode == '200') {
            var seatCnt = 0;
            var html = '';
            $('p.no-order').remove();
            if (data.data.length > 0) {
                var first_area_id = 0;
                for (var i = 0; i < data.data.length; i++) {
                    if (i == 0) {
                        first_area_id = data.data[i].orderDetails[0].areaId;
                    }
                    html += '<div class="swiper-slide">';
                    html += '<input type="hidden" name="area_id" value="' + data.data[i].orderDetails[0].areaId + '">';
                    html += '<input type="hidden" name="area_name" value="' + data.data[i].orderDetails[0].areaName + '">';
                    html += '<input type="hidden" name="seat_num" value="' + data.data[i].orderDetails.length + '">';
                    html += '<img src="https://wdoss.oss-cn-hangzhou.aliyuncs.com/wdczy/image/order.png" class="img_border02">';
                    html += '<h5>订单号</h5>';
                    html += '<h5 style="margin-bottom: 1.5vh;">' + data.data[i].tradeNo + '</h5>';
                    html += '<h3>座位区</h3>';
                    html += '<h3>' + data.data[i].orderDetails[0].areaName + '</h3>';
                    html += '<h3>座位编号</h3>';
                    html += '<div class="seatlist">';
                    if (data.data[i].isGroup == 1) {
                        html += '<h3>团队订座：' + data.data[i].orderDetails.length + '人</h3>';
                    } else {
                        for (var j = 0; j < data.data[i].orderDetails.length; j++) {
                            html += '<h3 style="font-size: .3rem; color: #DC143C;">' + data.data[i].orderDetails[j].seatName + '</h3>';
                        }
                    }
                    html += '</div>';
                    html += '<p class="dateTime">下单时间：' + data.data[i].createTime + '</p>';
                    html += '<img src="https://wdoss.oss-cn-hangzhou.aliyuncs.com/wdczy/image/haspayed.png" class="haspayed">';
                    html += '</div>';

                    seatCnt = seatCnt + data.data[i].orderDetails.length;
                }
                // $('#person p').html(seatCnt);
                $('.swiper-wrapper').html(html);
                var swiper = new Swiper('.swiper-container', {
                    navigation: {
                        nextEl: '.swiper-button-next',
                        prevEl: '.swiper-button-prev'
                    },
                    on: {
                        slideChangeTransitionEnd: function(){
                            var area_id = $('.swiper-slide-active input[name="area_id"]').val();
                            if (area_id == 12 || area_id == 1) {
                                $('.remind').show();
                            } else {
                                $('.remind').hide();
                            }
                        }
                    }
                });
                $('.bottom').show();
                if (first_area_id == 12 || first_area_id == 1) {
                    $('.remind').show();
                } else {
                    $('.remind').hide();
                }
            } else {
                $('.swiper-container').before('<p class="no-order">暂未预定座位</p>');
                $('.bottom').hide();
            }
        }
    }, 'json');
}
